import { defineStore } from 'pinia';
export const useMainStore = defineStore('main', {
	//开启持久化
	persist: {
		enabled: true,
		// storage:sessionStorage/localStorage,还可以自定义如下
		// https://seb-l.github.io/pinia-plugin-persist/
		// import Cookies from 'js-cookie'
		// const cookiesStorage: Storage = {
		//   setItem (key, state) {
		//     return Cookies.set('accessToken', state.accessToken, { expires: 3 })
		//   },
		//   getItem (key) {
		//     return JSON.stringify({
		//       accessToken: Cookies.getJSON('accessToken'),
		//     })
		//   },
		// }
		strategies: [
			{
				storage: sessionStorage,
				paths: ['num', 'token', 'userInfo'],
			},
		], //paths 是只将token，userName缓存到本地，可多添加或者删除，默认state中的全部数据
	},
	state() {
		return {
			num: 0,
			token: '',
			userInfo: {},
		};
	},
});
